/***********************************************************************
** Copyright (C) 2011 Anthony Naddeo <anthony.naddeo@gmail.com>
**
** This file is part of LinkedUp
**
** LinkedUp is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** LinkedUp is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this package; If not, see <http://www.gnu.org/licenses/>.
**
***********************************************************************/
import QtQuick 1.1
import com.meego 1.0
import "../components"

MyPage {
	id: root
	title: "Connections"
	tools: ToolBarLayout {
		ToolIcon { platformIconId: "toolbar-view-menu";
			anchors.right: parent===undefined ? undefined : parent.right
			onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
		}
		ToolIcon { platformIconId: "toolbar-back";
			anchors.left: parent===undefined ? undefined : parent.left
			visible: pageStack ? (pageStack.depth > 1 ? true : false) : false
			onClicked: {
				if(pageStack.depth > 1)
					pageStack.pop()
			}
		}
	}


	onProfileIDChanged: get(API.get_connections_by_id(profileID))
	onGetFinished: model.xml = responseText


	property string profileID

	SelfConnectionsModel{
		id: model
	}

	ListView{
		id: list
		clip: true
		spacing: 10
		anchors.fill: parent
		anchors.topMargin: borderHeight
		model:  model

		section.property: "firstName"
		section.criteria: ViewSection.FirstCharacter
		section.delegate: Label {
			text: section
			font.pointSize: 16

		}

		Rectangle{
			color: theme.inverted ? "white" : "black"
			anchors.right: parent.right
			anchors.top: parent.top
			anchors.bottom: parent.bottom
			width: 50
			opacity: list.moving  ? .5 : 0
			z: 10
			Behavior on opacity {NumberAnimation{duration:250}}
		}

		delegate: SelfConnectionsDelegate{
			onClicked: {
				var comp = Qt.createComponent("../profile/Profile.qml")
				var page = comp.createObject(root.parent, {"profileID": profileID})
				root.pageStack.push(page)

			}
		}

		SectionScroller {
			listView: list
		}
		ScrollDecorator {
			id: scroller
			flickableItem: list
		}
	}



}
